import java.util.LinkedList;

public class Soultion {
    //使用栈
    public boolean isValid(String s) {
        char[] chars = s.toCharArray();
        LinkedList<Character> stack = new LinkedList<>();
        for (char c : chars) {
            if(c == '(') stack.push(')');
            else if(c == '{') stack.push('}');
            else if(c == '[') stack.push(']');
            else if(stack.isEmpty() || c!= stack.pop()) return false;
        }
        return stack.isEmpty();
    }
}
